/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.service.car;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.unis.common.util.TemplateUtil;
import com.unis.dao.IDataSet4iBatis;
import com.unis.model.BaseModel;
import com.unis.model.car.CarRepair;

/**
 * @author CSJ (email:raulcsj@163.com)
 * @since 2013-01-11
 */
@Service("carrepairService")
public class CarRepairServiceImpl implements CarRepairService {

    private IDataSet4iBatis iDataSet4iBatis;

    /****************************************
     * Insert a instace of CarRepair
     ****************************************/
    public void insert(CarRepair carrepair) throws Exception {
        carrepair.setRepairid(TemplateUtil.genUUID());
        iDataSet4iBatis.insert(carrepair);
    }

    /****************************************
     * Update a instace of CarRepair
     ****************************************/
    public void update(CarRepair carrepair) throws Exception {
        iDataSet4iBatis.update(carrepair);
    }

    /****************************************
     * Delete a instace of CarRepair
     ****************************************/
    public void delete(CarRepair carrepair) throws Exception {
        iDataSet4iBatis.delete(carrepair);
    }

    /****************************************
     * Insert instaces of SysUser
     ****************************************/
    public void batchInsert(CarRepair carrepair) throws Exception {
        throw new RuntimeException("Not yet implement!");
    }

    /****************************************
     * Delete instaces of SysUser
     ****************************************/
    public void batchDelete(CarRepair carrepair) throws Exception {
        String statementId = carrepair.getStatmentId();
        String mainId = carrepair.getId();
        String[] ids = mainId.split(",");
        List<BaseModel> carrepairList = new ArrayList<BaseModel>();
        for (String id : ids) {
            CarRepair model = new CarRepair();
            model.setStatmentId(statementId);
            model.setId(id.trim());
            carrepairList.add(model);
        }
        iDataSet4iBatis.batchDelete(carrepairList);
    }

    /****************************************
     * Query instaces of CarRepair
     ****************************************/
    public List<BaseModel> queryAsList(CarRepair carrepair) throws Exception {
        String queryListStatement = "";
        if (carrepair.isPaging()) {
            queryListStatement = carrepair.getStatmentId();
            carrepair.setStatmentId("CarRepair.queryRecordsCount");
            BaseModel baseModel = iDataSet4iBatis.queryAsObject(carrepair);
            carrepair.setTotalCount(baseModel.getTotalCount());
            carrepair.setStatmentId(queryListStatement);
        }
        return iDataSet4iBatis.queryAsList(carrepair);
    }

    /****************************************
     * Query a instaces of CarRepair
     ****************************************/
    public BaseModel queryAsObject(CarRepair carrepair) throws Exception {
        return iDataSet4iBatis.queryAsObject(carrepair);
    }

    @Resource
    public void setiDataSet4iBatis(IDataSet4iBatis iDataSet4iBatis) {
        this.iDataSet4iBatis = iDataSet4iBatis;
    }
}
